const { handleClientAdapter } = require('../db-server/db-Adapter')
/**
 * 判断username是否存在
 * @param {*} res
 */
function isExitUsername(req, res, ogisticServiceData, username) {
  let dataSourceKey = ogisticServiceData.authDataSourceKey
  let client = handleClientAdapter(ogisticServiceData, dataSourceKey)
  let omuser = ogisticServiceData.authUserModel
  const user = new omuser(client)
  return new Promise((resolve, reject) => {
    user
      .query({
        where: `where username='${username}'`
      })
      .then(({ total }) => {
        if (total) {
          resolve(true)
        } else {
          resolve(false)
        }
      })
      .catch((err) => {
        reject(err)
      })
  })
}
exports.isExitUsername = isExitUsername
